#include "widget.h"
#include "ui_widget.h"
#include "gamecontrol.h"
Widget* Widget::widget=nullptr;
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setFixedSize(1380,860);
    widget =this;

}

Widget::~Widget()
{
    delete ui;
}
void Widget::keyReleaseEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_Left){
        GameControl::m_a=0;
    }
    else if(event->key() == Qt::Key_Up){
        GameControl::m_w=0;
    }
    else if(event->key() == Qt::Key_Down){
        GameControl::m_s=0;
    }
    else if(event->key() == Qt::Key_Right){
        GameControl::m_d=0;
    }
    if(event->key() == Qt::Key_D&&!event->isAutoRepeat()){

        GameControl::instance->PlayerBulletShoot(1);
    }
    else if(event->key() == Qt::Key_A&&!event->isAutoRepeat()){
        GameControl::instance->PlayerBulletShoot(2);
    }
}
void Widget::keyPressEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_Left){
        GameControl::m_a=1;
    }
    else if(event->key() == Qt::Key_Up){
        GameControl::m_w=1;
    }
    else if(event->key() == Qt::Key_Down){
        GameControl::m_s=1;
    }
    else if(event->key() == Qt::Key_Right){
        GameControl::m_d=1;
    }
    GameControl::instance->m_timer->stop();
    GameControl::instance->m_timer->start(GameDfine::m_time);

}
